<template>
	<div>
		<v-dialog v-model="emailModel.sendEmailDialogVisable" max-width="800px">
			<v-card>
				<v-card-title>
					邮件发送
				</v-card-title>
				<v-alert dense type="info" class="text-left">
					{{emailModel.label}}
				</v-alert>
				<v-form>
					<v-card-text>
						<v-text-field label="邮件标题" placeholder="邮件标题" :style="this.temp.title" outlined v-model="emailView.title">
						</v-text-field>
						<v-select :items="departmentList" label="选择部门" persistent-hint small-chips dense outlined
							@input="departmentChangeEvent"></v-select>
						<v-combobox v-model="emailView.receiveIfnos" :items="tempReceiveUserList" label="选择被发送人"
							outlined multiple chips></v-combobox>
						<uploadfile></uploadfile>
						<v-textarea outlined name="input-7-4" label="邮件内容" :value="emailView.body"
							v-model="emailView.body"></v-textarea>

					</v-card-text>
					<v-card-actions>
						<v-spacer></v-spacer>
						<v-btn color="primary" text :disabled="emailView.title==null" @click="sendEmail">
							发送
						</v-btn>
						<v-btn color="primary" text @click="emailModel.sendEmailDialogVisable = false">
							关闭
						</v-btn>
					</v-card-actions>
				</v-form>
			</v-card>
		</v-dialog>

	</div>
</template>

<script>
	import uploadfile from './UploadFile.vue'
	export default {
		name: 'mes_sendEmail',
		components: {
			uploadfile
		},
		props: {
			callBack: {
				type: Function, //参数类型：函数
			},
			emailModel: {
				sendEmailDialogVisable: false,
				//需要查询表的id
				queryIds: [],
				//是否发送自己上传的附件，（true:queryIds的值就不用了，而是使用自己上传的附件）
				isSendSelfUploadFiles: false,
				GetDepartmentUserToSelectUrl: '',
				SendEmailUrl: '',
				label: '请选中开料信息信息后录入邮件内容和标题',
				title: '',
				body: '',
				jsonM: ''
			}
		},
		watch: {
			emailModel: {
				handler(newVal) {
					this.$emit('update:emailModel', newVal)
					this.emailView.title = this.emailModel.title
					this.emailView.body = this.emailModel.body
					this.temp=this.emailModel
					this.loadDepartmentList()
				},
				deep: true
			},
		},
		data: () => ({
			emailView: {
				querInfo: {}
			},
		 temp:{},
			tempReceiveUserList: [],
			departmentList: []
		}),


		methods: {
			async loadDepartmentList() {
				if (!this.emailModel.sendEmailDialogVisable)
					return

				var response = await this.$httpRequest({
					url: this.emailModel.GetDepartmentUserToSelectUrl,
					method: 'get',
				})
				if (response.status == 1) {
					this.departmentList = response.data
				}
			},

			departmentChangeEvent(item) {
				if (item != null) {
					this.tempReceiveUserList = item
				}
			},
			//发送邮件对话框
			async sendEmail() {
				this.emailView.querInfo.queryIds = this.emailModel.queryIds
				this.emailView.jsonM = this.emailModel.jsonM
				this.emailView.isAttachmentInfo = true
				var response = await this.$httpRequest({
					url: this.emailModel.SendEmailUrl,
					method: 'post',
					data: this.emailView
				})

				if (response.status == 1) {
					this.close()
					this.$message.success(response.info)
					this.$props.callBack(true)
				} else {
					this.$message.error(response.info)
				}
			},
			close() {
				this.emailModel.sendEmailDialogVisable = false
				this.emailView.title = ''
				this.emailView.body = ''
				this.emailView.querInfo = {}
				this.emailModel.queryIds = []
			},
		}
	}
</script>

<style>
</style>
